package com.wu.enums;


import com.wu.exception.EnumInterface;

/**
 * 系统编码枚举类
 */
public enum SystemEnum implements EnumInterface<String, String, String> {

    SUCCESS("S000", "success", "成功"),
    FAILED("S001", "fail", "失败"),
    INVALID("S002", "login expired", "登录失效，请重新登录"),
    ACCESS_DENIED("S003", "no permission", "权限不足"),
    SYSTEM_ERROR("S004", "systen error", "系统异常"),
    PARAM_VALIDE_FAIL("S005", "params error", "参数校验错误"),
    UN_ERROR("S006", "unknown error", "未知错误"),

    REPEAT_OPERATION("S007", "repeat_operation", "请勿重复操作"),
    DATA_NOT_EXIST("S008", "data_not_exist", "数据不存在"),

    /**
     * 权限相关枚举
     */
    ROLE_EXIST("S207", "role exist", "角色已存在，请更换另一个名称"),
    RESOURCE_EXIST("S201", "resource exist", "权限资源已存在，请更换另一个名称"),
    RESOURCE_BE_USED("S202", "resource be used", "权限资源正在被使用，无法删除"),
    RESOURCE_NO_EXIST("S203", "resource no exist", "权限资源不存在或已删除"),
    RESOURCE_HAVE_SON("S204", "resource have son", "权限资源存在子节点，无法删除"),
    POSITION_EXIST("S205", "position be used", "职务已存在，请更换另一个名称"),
    POSITION_BE_USED("S206", "position be used", "职务正在被使用，无法删除"),

    DEPARTMENT_NOT_EXIST("S211", "department_not_exist", "部门不存在"),
    ROLE_NOT_EXIST("S212", "role_not_exist", "角色不存在"),
    POSITION_NOT_EXIST("S213", "position_not_exist", "职位不存在"),
    /**
     * 人员相关
     */
    USER_NOT_EXIST("S301", "user_not_exist", "人员不存在"),




    ;
    /**
     * 错误编号
     */
    private String code;

    /**
     * 错误信息
     */
    private String msg;

    /**
     * 错误描述
     */
    private String desc;

    private SystemEnum(String code, String msg, String desc) {
        this.code = code;
        this.msg = msg;
        this.desc = desc;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    @Override
    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public void setDesc(String desc) {
        this.desc = desc;
    }


    public static String getValueByKey(String key) {
        for (SystemEnum e : values()) {
            if (e.getCode().equals(key)) {
                return e.getMsg();
            }
        }
        return UN_ERROR.getMsg();
    }

    public static String getKeyByValue(String value) {
        for (SystemEnum e : values()) {
            if (e.getCode().equals(value)) {
                return e.getMsg();
            }
        }
        return UN_ERROR.getCode();
    }

}
